﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace Lead2012.Business
{
    public class FieldCustomLeadFormTypeRepository
    {
        // Create an instance of entity
        Lead2012Entities entities = new Lead2012Entities();
                
        public FieldCustomLeadFormType GetSingle(int fieldId, int typeId)
        {
            return (from _object in entities.FieldCustomLeadFormTypes 
                    where _object.FieldId == fieldId && _object.TypeId == typeId 
                    select _object).FirstOrDefault();
        }   
        public int GetSingle(int fieldId)
        {
            var item = (from _object in entities.FieldCustomLeadFormTypes 
                    where _object.FieldId == fieldId
                    select _object).FirstOrDefault();

            if (item != null)
                return item.TypeId;

            return 0;
        }

        public void Create(FieldCustomLeadFormType _object)
        {
            entities.AddToFieldCustomLeadFormTypes(_object);
            entities.SaveChanges();
        }

        public void Delete(int fieldId, int typeId)
        {
            try
            {
                var _object = (from _list in entities.FieldCustomLeadFormTypes
                               where _list.FieldId == fieldId && _list.TypeId == typeId
                               select _list).First();
                entities.DeleteObject(_object);
                entities.SaveChanges();
            }
            catch
            {
            }
        }

        public void Delete(int fieldId)
        {
            try
            {
                var _object = (from _list in entities.FieldCustomLeadFormTypes 
                               where _list.FieldId == fieldId
                               select _list).First();
                entities.DeleteObject(_object);
                entities.SaveChanges();
            }
            catch
            {
            }
        }
    }
}